# This file is part of The Vu Toolkit.
#
# The Vu Toolkit is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 3.0 of the License, or (at your option) any later version.
#
# The Vu Toolkit is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with The Vu Toolkit; if not, write to the Free
# Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
# 02111-1307 USA.
#
# Copyright © Zak Fenton 2008
#

require 'Vu/Gadget'

module Vu
	class Frame < Gadget
		@content = nil
		attr_reader :content
		
		def content= (c)
			if @content
				@content.detach_from_parent!
			end
			@content = c
			@content.attach_to_parent! self
		end
		
		def children
			if @content
				[@content]
			else
				[]
			end
		end
		
		def initialize
			@border_width = 0
			@border_height = 0
		end
		
		def perform_layout!
			if @content
				@content.x_origin = @border_width
				@content.y_origin = @border_height
				@content.resize!(width-(@border_width*2), height-(@border_height*2))
			end
		end
		
		def resize! (w, h)
			super(w,h)
			perform_layout!
		end
		
		def resize_border! (w, h)
			if w != @border_width or h != @border_width
				@border_width = w
				@border_height = h
				perform_layout!
			end
		end
	end
end
